﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace Web_Demo
{
    public class dataconnect
    {
        public dataconnect()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public SqlConnection conn = new SqlConnection();
    public void ketNoi()
    {
        if (conn.State != ConnectionState.Open)
        {
            conn.ConnectionString = @"Data Source=VJKJNG-PC;Initial Catalog=DMS_DEMO;Integrated Security=True";
            conn.Open();
        }
    }
    public object executeScalar(string query)
    {
        object ob = null;
        try
        {
            ketNoi();
            SqlCommand comm = new SqlCommand(query, conn);
            ob = comm.ExecuteScalar();
        }
        catch (Exception)
        {
        }
        conn.Close();
        return ob;

    }
    public object executeNonQuery(string query)
    {
        ketNoi();
        SqlCommand comm = new SqlCommand(query, conn);
        object ob = comm.ExecuteNonQuery();
        conn.Close();
        return ob;
    }
    public SqlDataReader executeReader(string query)
    {
        ketNoi();
        SqlCommand comm = new SqlCommand(query, conn);
        SqlDataReader ob = comm.ExecuteReader();
        return ob;
    }
    public DataSet executeDataSet(string query)
    {
        ketNoi();
        SqlDataAdapter da = new SqlDataAdapter(query, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        conn.Close();
        return ds;
    }
    public DataTable executeDataTable(string query)
    {
        ketNoi();
        SqlDataAdapter da = new SqlDataAdapter(query, conn);
        DataTable ds = new DataTable();
        da.Fill(ds);
        conn.Close();
        return ds;
    }
    }
}